﻿using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using Prompts.Service.PromptService;
using Prompts.Service.PromptService.Construction;
using Prompts.Service.ReportCatalogService.Construction;

namespace Prompts.Service.Construction
{
    public class WcfServiceInstanceProvider : IInstanceProvider
    {
        private readonly Type _type;

        public WcfServiceInstanceProvider(Type type)
        {
            _type = type;
        }

        public object GetInstance(InstanceContext instanceContext)
        {

            return GetInstance(instanceContext, null);
        }

        public object GetInstance(InstanceContext instanceContext, Message message)
        {
            if(_type == typeof(ChildPromptLevelService))
            {
                return ChildPromptLevelServiceInjector.Inject();
            }
            if(_type == typeof(PromptSelectionService))
            {
                return PromptSelectionServiceInjector2.Inject();
            }
            if(_type == typeof(PromptService.PromptService))
            {
                return PromptServiceInjector.Inject();
            }
            if(_type == typeof(ReportCatalogService.ReportCatalogService))
            {
                return ReportCatalogServiceInjector.Inject();
            }
            throw new Exception();
        }

        public void ReleaseInstance(InstanceContext instanceContext, object instance)
        {
        }
    }
}